#!/usr/bin/env python

import time
import logging
from binance.lib.utils import config_logging
from binance.um_futures import UMFutures
from binance.websocket.um_futures.websocket_client import UMFuturesWebsocketClient

config_logging(logging, logging.DEBUG)


def message_handler(_, message):
    print(message)

key = "z4U7noE4iEkLPVi3z02yq4iKvnUkeOslYXRzNKQhFFMni3dzsjmdjfQXZWvuS9Am"
secret = "mEEpNcWyeSEcHbvkpPTPGJRWgTX0iS7QjCA2aaMHUTgyOuCRPTm8Y7HByPnPaWQ5"

proxies = { 'https': 'http://127.0.0.1:7890' }
# hmac_client = UMFutures(key=key, secret=secret,proxies=proxies)
# logging.info(hmac_client.account(recvWindow=6000))

api_key = ""
client = UMFutures(key=key, secret=secret,proxies=proxies)
response = client.new_listen_key()

logging.info("Listen key : {}".format(response["listenKey"]))

ws_client = UMFuturesWebsocketClient(on_message=message_handler,proxies=proxies)

ws_client.user_data(
    listen_key=response["listenKey"],
    id=1,
)

time.sleep(3000)

logging.debug("closing ws connection")
ws_client.stop()
